package com.thoughtworks.mobile;

import android.content.Context;
import android.graphics.*;
import android.graphics.Path;
import android.view.View;


public class Ring extends View{

    private int radius;
    private float startAngle, sweepAngle;
    String text;
    public static final int CENTER_X = 240;
    public static final int CENTER_Y = 220;

    public Ring(Context context, int radius, float startAngle, float sweepAngle, String text){
        super(context);
        this.radius = radius;
        this.startAngle = startAngle;
        this.sweepAngle = sweepAngle;
        this.text = text;

    }

    @Override
    protected void onDraw(Canvas canvas){
//        super.onDraw(canvas);

        final Paint paint = getPaint();

        canvas.drawLine(5, CENTER_Y, CENTER_X +radius+25, CENTER_Y, paint);
        canvas.drawLine(CENTER_X, 5, CENTER_X, CENTER_Y +radius+15, paint);

        final RectF oval1 = new RectF(CENTER_X -radius, CENTER_Y -radius, CENTER_X +radius, CENTER_Y +radius);
        canvas.drawArc(oval1, startAngle, sweepAngle, false, paint);

        paint.setStrokeWidth(1);
        paint.setTextSize(16);

        int offset = 3;
        final  RectF oval2 = new RectF(CENTER_X -radius+offset, CENTER_Y -radius+offset, CENTER_X +radius-offset, CENTER_Y +radius-offset);
        Path path = new Path();
        path.addArc(oval2, -85, sweepAngle);

        canvas.drawTextOnPath(text, path, 0, 0, paint);

    }

    private Paint getPaint() {
        final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(2);
        paint.setStyle(Paint.Style.STROKE);
        return paint;
    }

}
